package twobranchTree.issymmetirc;

import twobranchTree.preorderTraversal.TreeNode;

/**
 * @Date 2020/2/23
 * @author 王光浩
 * @Thinking 使用递归方法。
 */
public class MyMethodTwo {
	private boolean judge=true;
	public boolean isSymmetric(TreeNode root) {
		if(root==null)return judge;
		recursively(root.left,root.right);
		return judge;
	}
	//对左右两颗子树进行遍历，（按照对称的顺序进行遍历）
	private void recursively(TreeNode left,TreeNode right) {
		if(left==null && right==null)return;
		else if((left==null && right!=null) || (left!=null && right==null)){  //节点不对称
			this.judge=false;
		}
		else if(left.val!=right.val) {   //对称节点值不相同
			this.judge=false; 
			return;
		}
		else {
			recursively(left.left,right.right);
			recursively(left.right,right.left);
		}
		
	}
}
